package app.netant.finishbook.blblgl;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class BlblglDetail extends BaseDetail {

	public BlblglDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.blblgl.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("body #container .main-wrap .col-1 .detail .cont h3");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts1 = this.select("body #container .main-wrap .col-1 .detail .cont dl.info dt");
		Elements parts2 = this.select("body #container .main-wrap .col-1 .detail .cont dl.info dd");
		for(int i=0;i<parts1.size();i++){
			if(parts2.size()>i){
				String tagName = parts1.get(i).text().trim();
				String tagValue = parts2.get(i).text().trim();
				if(tagName.endsWith("：")){
					tagName = tagName.substring(0,tagName.length()-1);
				}
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("body #container .main-wrap .col-1 .detail .cont #xs-text #part-intro");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("body #container .main-wrap .col-1 .list-content .se-list .btn-group .alink center a.btnHook.btn_A");
		if(parts.size()>0){
			String url = parts.get(0).attr("href");
			if(url.startsWith("/")){
				url = this.preHref + url;
			}
			System.out.println("【Url】:"+url);
			BlblglDetail detail = new BlblglDetail(url);
			String href = detail.stepHref();		
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	public String stepHref(){
		Elements parts = this.select("center table tbody tr td center a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			return href;
		}
		return null;
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("body #container .subnav a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		BlblglDetail detail = new BlblglDetail("http://www.blblgl.com/lingyixuanhuan/39099.html");
		detail.test();
	}



}
